<meta charset="UTF-8">
<?php
require('lib/init.php');
// 判断用户是否登录
if (!acc()) {
    header('Location:login.php');
}
//添加栏目PHP
if (empty($_POST)){
    include (ROOT . '/view/admin/catadd.html');
}else{
//    检测栏目是否为空
    $cat['cat_name'] =trim($_POST['catname']);
    if (empty($cat['cat_name'])){
        error  ('分类不能为空','javascript:history.back(-1)');
        exit();
    }
//  检测栏目是否已经存在
    $sql = "select * from cat where cat_name = '$cat[cat_name]'";
    $rs = mGetRow($sql);
    if ($rs != 0){
        error  ('分类已经存在','javascript:history.back(-1)');
        exit();
    }
    if (!mExec('cat',$cat,'insert')){
        error('分类添加失败！','javascript:history.back(-1)');
    } else{
       succ('分类添加成功！','catlist.php');
    }


}


?>
